package com.qf.cx.simplenms.core.spi.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

import org.springframework.beans.factory.annotation.Autowired;

import com.qf.cx.simplenms.core.spi.Updater;
import com.qf.cx.simplenms.core.util.ModelUtils;
import com.qf.cx.simplenms.persist.entity.ReaderEntity;
import com.qf.cx.simplenms.persist.service.api.ReaderService;
import com.qf.cx.simplenms.reader.api.ReaderManager;
import com.qf.cx.simplenms.reader.model.ReaderModel;

public class ReaderUpdater implements Updater {
	@Autowired
	private ReaderService readerService;

	@Autowired
	private ReaderManager readerManager;

	@Override
	public void update() {
		List<ReaderEntity> readers = readerService.getReaders();
		List<ReaderModel> list = new ArrayList<>();
		readers.forEach(new Consumer<ReaderEntity>() {
			@Override
			public void accept(final ReaderEntity t) {
				ReaderModel readerModel = ModelUtils.createReaderModel(t);
				list.add(readerModel);
			}

		});
		readerManager.updateCache(list);
	}

}
